package com.mipo.client.javase.company.flytek.jinzhou.openapi;

import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/*
 * edc-open-api:
 * 	client_id: cba0d5243a9d4a7daea0c8f594752f02
 * 	client_secret: ef1821da260537e5175c22f4d3a423a1
 * desk-top:
 * 	client_id: 4d3d3d741c524a38aab4845280040f43
 * 	client_secret: bde9a1723d3c3158adcc97dde7413403
 * disk:
 * 	client_id: be6427c7bc90493fa16e4cac34e334bb
 * 	client_secret:1e23a983189276da32b3833a43df697a
 */
public class TestMain3 {
	public static void main(String[] args) throws Exception {
		// 获取token
		String url1 = "http://open.jztest.changyan.cn/authorization-token-server/oauth/token?client_id=4d3d3d741c524a38aab4845280040f43&client_secret=bde9a1723d3c3158adcc97dde7413403&grant_type=client_credentials";
		// 根据用户名获取用户信息 core.user.get
		String url2 = "http://open.jztest.changyan.cn/api?format=json&appkey=be6427c7bc90493fa16e4cac34e334bb&version=1.0&access_token=3284eedf-e0f9-43f1-8da3-6217ec698ce2&method=core.user.get&key=loginName&value=szadmin";
		// 第三方厂商定制接口：验证用户名密码 dslx.user.validat
		String url3 = "http://open.jztest.changyan.cn/api?format=json&appkey=cba0d5243a9d4a7daea0c8f594752f02&version=1.0&access_token=111382b0-bdb5-45e1-a269-07db959c8bd0&method=dslx.user.validate&loginName=szadmin&password=123456";
		// 盘服务上传文件后索引：pan.file.uploadafter
		String url4 = "http://open.jztest.changyan.cn/api?format=json&appkey=cba0d5243a9d4a7daea0c8f594752f02&version=1.0&access_token=61f5418f-5a91-4cc8-934e-6fa3d7d1a594&method=pan.file.uploadafter&key=loginName&value=szadmin";
		// 获取单个资源信息：ersp.resource.get
		String url5 = "http://open.jztest.changyan.cn/api?format=json&appkey=4d3d3d741c524a38aab4845280040f43&version=1.0&access_token=85434082-3386-49fa-ab75-ec118e793bf7&method=ersp.resource.list&id=07a4c3a6dc3740208fb89460a62968c4";
		
		
		
		excuteGetRequest(url5);
	}
	
	public static void excuteGetRequest(String url) throws Exception {
		CloseableHttpClient httpClient = HttpClients.createDefault();
		HttpGet httpGet = new HttpGet(url);
		CloseableHttpResponse response = httpClient.execute(httpGet); // 4.3版本不设置超时的话，一旦服务器没有响应，等待时间N久(>24小时)。
		HttpEntity entity = response.getEntity(); // 返回报文实体
		StatusLine status = response.getStatusLine();
		System.out.println("返回的状态码为：" + status); // 具体返回码(200)为status.getStatusCode(); 
		String ret = EntityUtils.toString(entity); // 将返回报文实体转换为字符串
		System.out.println("返回的报文为：" + ret);
		EntityUtils.consume(entity);  // 释放是否可以去掉？
		response.close(); // 关闭资源,可以写在finally里
		httpGet.releaseConnection(); // 释放资源
		httpClient.close(); // 关闭资源
	}
}
